The ImageCodecBeginBand function allows your image decompressor component to save information about a band before decompressing it. For example, your image decompressor component can change the value of the codecData pointer if not all of the data for the band needs to be decompressed. The base image decompressor preserves any changes your image decompressor component makes to any of the fields in the ImageSubCodecDecompressRecord or CodecDecompressParams structures.
The ImageCodecBeginBand function is never called at interrupt time. If your component supports asynchronous scheduled decompression, it may receive more than one ImageCodecBeginBand call before receiving an ImageCodecDrawBand call.
A sample implementation of ImageCodecBeginBand is shown in Listing 4 .
Listing 4 Sample implementation of ImageCodecBeginBand
pascal ComponentResult ImageCodecBeginBand (
ComponentInstance ci,
CodecDecompressParams *p,
ImageSubCodecDecompressRecord *drp,
long flags)
{
ExampleDecompressRecord *mydrp = drp->userDecompressRecord;
long numLines,numStrips;
long stripBytes;
short width;
short y;
OSErr result = noErr;
Ptr cDataPtr;
/* initialize some local variables */
width = (*p->imageDescription)->width;
numLines = p->stopLine - p->startLine; /* number of scanlines in */
/* this band */
numStrips = (numLines+1)>>1; /* number of strips in this band */
stripBytes = ((width+1)>>1) * 5; /* number of bytes in one */
/* strip of blocks */
cDataPtr = drp->codecData;
/*
* If skipping some data, just skip it here. We can tell because
* firstBandInFrame says this is the first band for a new frame, and
* if startLine is not zero, then that many lines were clipped out.
*/
if ( (p->conditionFlags & codecConditionFirstBand) && p->startLine != 0 ) {
if ( p->dataProcRecord.dataProc ) {
for ( y=0; y < p->startLine>>1; y++ ) {
if ( (result=CallICMDataProc(p->dataProcRecord.dataProc,&cDataPtr,stripBytes,
drp->dataProcRecord.dataRefCon)) != noErr ) {
result = codecSpoolErr;
goto bail;
}
cDataPtr += stripBytes;
}
} else
cDataPtr += (p->startLine>>1) * stripBytes;
}
drp->codecData = cDataPtr;
mydrp->width = width;
mydrp->numStrips = numStrips;
mydrp->srcDataIncrement = stripBytes;
mydrp->baseAddrIncrement = drp->rowBytes<<1;
mydrp->glob = (void *)storage;
/* figure out our dest pixel format and select the
correct DecompressStripProc */
switch(p->dstPixMap.pixelFormat) {
case 0: // old case where planebytes
// is not set by codecmanager
case k32ARGBPixelFormat:
mydrp->decompressStripProc = DecompressStrip32ARGB;
break;
case k32ABGRPixelFormat:
mydrp->decompressStripProc = DecompressStrip32ABGR;
break;
case k32BGRAPixelFormat:
mydrp->decompressStripProc = DecompressStrip32BGRA;
break;
case k32RGBAPixelFormat:
mydrp->decompressStripProc = DecompressStrip32RGBA;
break;
default:
bail;
break;
}
bail:
return result;
}
| Previous | Chapter Contents | Chapter Top | Next |